<?php
/**
 * Created by PhpStorm.
 * User: HS032
 * Date: 2020/8/22
 * Time: 13:21
 */

namespace ticket\modules\backend\controllers;

use ticket\libs\Tools;
use ticket\modules\backend\models\TicketDate;
use Yii;

/*** 门票日期价格，库存
 * Class TicketDateController
 * @package ticket\modules\backend\controllers
 */
class TicketDateController extends BasicController
{

    /*** 获取门票库存日期信息
     * @return false|string
     */
    public function actionTicketDateInfo()
    {
        if (Yii::$app->request->isPost){
            $post = Yii::$app->request->post();
            $tid = isset($post['tid'])?$post['tid']:'';
            if (empty($tid) or !is_numeric($tid)){
                return Tools::showRes(99,'参数有误');
            }

            $dateModel = new TicketDate();

            $ticketDateList = $dateModel->getTicketDateInfo($tid);

            return Tools::showRes(0,'success',[
                'ticketDateList' => $ticketDateList,
            ]);
        }
    }


    /*** 添加、修改门票库存日期
     * @return false|string
     */
    public function actionSetTicketDate()
    {
        if (Yii::$app->request->isPost){
            $post = Yii::$app->request->post();
            $dateModel = new TicketDate();
            $username = $this->userInfo['username'];
            if (!$ok = $dateModel->setTicketDateInfo($username,$post)){
                if ($dateModel->hasErrors()){
                    return Tools::showRes(10044,'添加库存日期失败');
                }else{
                    return Tools::showRes(10045,'添加库存日期失败');
                }
            }
            return Tools::showRes(0,'success',[
                'ok' => $ok
            ]);
        }
    }

}